package com.telsoft.data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

public class DAOHelper {
	private String strUser;
	private String strPass;
	String strConnection;

	public DAOHelper() {
		super();
		strUser = ResourceBundle.getBundle("connection").getObject("SEC_User")
				.toString();
		strPass = ResourceBundle.getBundle("connection").getObject("SEC_Pass")
				.toString();
		strConnection = ResourceBundle.getBundle("connection")
				.getObject("SEC_ConnectionString").toString();
		// TODO Auto-generated constructor stub
	}

	public Connection getConnection() throws SQLException {
		DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
		return DriverManager.getConnection(strConnection, strUser, strPass);
	}

	public Statement getStatement(Connection conn) throws SQLException {
		if (conn != null) {
			return conn.createStatement();
		} else {
                return null;
            }
	}

	public PreparedStatement getPreparedStatement(Connection conn, String sql)
			throws SQLException {
		if (conn != null) {
			return conn.prepareStatement(sql);
		} else {
                                return null;
                            }
	}

	public void closeStatement(Statement stm) throws SQLException {
		if (stm != null) {
                stm.close();
            }
	}

	public void closePreparedStatement(PreparedStatement preStm)
			throws SQLException {
		if (preStm != null) {
                                preStm.close();
                            }
	}
	public void closeConnection(Connection conn) throws SQLException{
		if(conn != null) {
                conn.close();
            }
	}
        public void closeResultSet(ResultSet rs) throws SQLException{
            if(rs != null){
                rs.close();
            }
        }
}
